package com.njthird.busi.controller;

import java.util.List;

import com.njthird.common.utils.DateUtils;
import com.njthird.common.utils.SecurityUtils;
import com.njthird.common.utils.uuid.IdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.njthird.common.annotation.Log;
import com.njthird.common.core.controller.BaseController;
import com.njthird.common.core.domain.AjaxResult;
import com.njthird.common.enums.BusinessType;
import com.njthird.busi.domain.BusiStockaccts;
import com.njthird.busi.service.IBusiStockacctsService;
import com.njthird.common.utils.poi.ExcelUtil;
import com.njthird.common.core.page.TableDataInfo;

/**
 * 券商账户管理Controller
 * 
 * @author njthird
 * @date 2020-08-11
 */
@RestController
@RequestMapping("/busi/stockaccts")
public class BusiStockacctsController extends BaseController
{
    @Autowired
    private IBusiStockacctsService busiStockacctsService;

    /**
     * 查询券商账户管理列表
     */
    @PreAuthorize("@ss.hasPermi('busi:stockaccts:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusiStockaccts busiStockaccts)
    {
        startPage();
        List<BusiStockaccts> list = busiStockacctsService.selectBusiStockacctsList(busiStockaccts);
        return getDataTable(list);
    }

    /**
     * 导出券商账户管理列表
     */
    @PreAuthorize("@ss.hasPermi('busi:stockaccts:export')")
    @Log(title = "券商账户管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusiStockaccts busiStockaccts)
    {
        List<BusiStockaccts> list = busiStockacctsService.selectBusiStockacctsList(busiStockaccts);
        ExcelUtil<BusiStockaccts> util = new ExcelUtil<BusiStockaccts>(BusiStockaccts.class);
        return util.exportExcel(list, "stockaccts");
    }

    /**
     * 获取券商账户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('busi:stockaccts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(busiStockacctsService.selectBusiStockacctsById(id));
    }

    /**
     * 新增券商账户管理
     */
    @PreAuthorize("@ss.hasPermi('busi:stockaccts:add')")
    @Log(title = "券商账户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusiStockaccts busiStockaccts)
    {
        busiStockaccts.setId(IdUtils.fastSimpleUUID());
        busiStockaccts.setCreateBy(SecurityUtils.getUsername());
        busiStockaccts.setCreateTime(DateUtils.getNowDate());
        return toAjax(busiStockacctsService.insertBusiStockaccts(busiStockaccts));
    }

    /**
     * 修改券商账户管理
     */
    @PreAuthorize("@ss.hasPermi('busi:stockaccts:edit')")
    @Log(title = "券商账户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusiStockaccts busiStockaccts)
    {
        busiStockaccts.setUpdateBy(SecurityUtils.getUsername());
        busiStockaccts.setUpdateTime(DateUtils.getNowDate());
        return toAjax(busiStockacctsService.updateBusiStockaccts(busiStockaccts));
    }

    /**
     * 删除券商账户管理
     */
    @PreAuthorize("@ss.hasPermi('busi:stockaccts:remove')")
    @Log(title = "券商账户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(busiStockacctsService.deleteBusiStockacctsByIds(ids));
    }
}
